<?php

class ControladorCategoria extends ControladorFather {

    public $categoria;

    public function __construct() {
        $this->categoria = new Categoria(host, dbname, port, user, pass);
    }

    public function index() {
        
    }
    
    public function listC($param = 0) {
        if ($param != "") {
            if ($param[0] == 0) {
                $result = $this->categoria->find(array('order' => array('name')));
                include_once("View/Categoria/listC.php");
            }
        }
    }

    public function add() {
        
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            
            $data = array(
                'name'=>$_POST['namePub']
            );
            
            if($this->categoria->save(0,$data))
                $result = 1;
            else
                $result = 0;
        }
        include_once("View/Categoria/add.php");
    }
    
    public function edit($param){
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            
            $data = array(
                'name'=>$_POST['nomePub']
            );
            
            if($this->categoria->save($param[0],$data))
                $result = 1;
            else
                $result = 0;
        }
        $date = $this->categoria->findById($param[0]);
        include_once("View/Categoria/edit.php");
    }
    
    public function delete($param){
        
        $this->categoria->delete($param[0]);
        header("Location: index.php?c=Categoria&a=listC&p=0");
    }

}

?>
